﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package ZLocalization {

    public class LocalizationObjectToken extends LocalizationToken {

        public static const GENDERS:Object = {
            masc:0,
            fem:1,
            neuter:2
        };

        protected static var VALID_ATTRIUBTES:Array = ["plural", "singular", "count", "indefinite", "definite", "masc", "fem", "common", "neuter"];
        protected static var LOOKUP_ATTRIBUTES:Array = [["indefinite", "definite"], ["singular", "plural"], ["accusative"]];

        private const NO_COUNT:int = -1;
        private const DEFAULT_GENDER:String = "masc";
        private const SINGULAR:String = "singular";
        private const PLURAL:String = "plural";
        private const ATTRIBUTE_DELIM:String = ",";

        protected var m_locString:LocalizedString;

        public function LocalizationObjectToken(_arg1:LocalizedString, _arg2:String="", _arg3:int=-1){
            this.m_locString = _arg1;
            if (_arg2 != ""){
                m_attributes = m_attributes.concat(_arg2.split(this.ATTRIBUTE_DELIM));
            };
            if (_arg3 != this.NO_COUNT){
                m_attributes.push(((_arg3 == 1)) ? this.SINGULAR : this.PLURAL);
            };
            if (((this.m_locString) && (!((this.m_locString.gender == null))))){
                m_attributes.push(this.m_locString.gender);
            };
        }
        protected static function validateAttributes(_arg1:Array):void{
            var _local2:Array = Utilities.arrayDiff(_arg1, VALID_ATTRIUBTES);
            if (_local2.length != 0){
                throw (new Error(("Invalid token attributes: " + _local2.join(","))));
            };
        }

        override public function getString():String{
            var _local3:Array;
            var _local1:Array = new Array();
            var _local2:int;
            while (_local2 < LOOKUP_ATTRIBUTES.length) {
                _local3 = Utilities.arrayIntersect(m_attributes, LOOKUP_ATTRIBUTES[_local2]);
                if (_local3.length > 0){
                    if (_local3.length == 1){
                        _local1.push(_local3[0]);
                    } else {
                        throw (new Error("Token attributes lead to an ambiguous variant."));
                    };
                };
                _local2++;
            };
            return (this.m_locString.getVariation(_local1.join("_")));
        }

    }
}//package ZLocalization 
